
import { getConversationRequest, getListRequest } from '@/api/im-conversation'

const iMUser = {
  namespaced: true,
  state: {
    info: null,
    list: null
  },

  getters: {},

  mutations: {
    SET_INFO: (state, info) => {
      state.info = info
    },

    SET_LIST: (state, list) => {
      state.list = list
    }

  },

  actions: {
    getConversationAction({ commit }, parameters) {
      return new Promise((resolve, reject) => {
        getConversationRequest(parameters)
          .then(response => {
            const info = response.result
            commit('SET_INFO', info)
            resolve(response)
          })
          .catch(error => {
            reject(error)
          })
      })
    },

    getListAction({ commit }, parameters) {
      return new Promise((resolve, reject) => {
        getListRequest(parameters)
          .then(response => {
            if (response.result && response.result.records) {
              const records = response.result.records
              commit('SET_LIST', records)
            }

            resolve(response)
          })
          .catch(error => {
            reject(error)
          })
      })
    }


  }
}

export default iMUser
